function HCP_LRR_predictable_behavior_step1(LRR_dir, Nperm, intrim_csv, restricted_csv, subj_ls)

    % HCP_LRR_predictable_behavior_step1(LRR_dir, Nperm, intrim_csv, restricted_csv, subj_ls)
    %
    % Permute behavioral scores across subjects, considering the family structures (multi-level block 
    % permutation). Muilti-level block permutation requires the FSL PALM package.
    % Run elastic net (LRR) on the permuted scores to test the predictability of the original 
    % KRR model.
    %
    % Inputs:
    %   - LRR_dir
    %     The directory which contains the elastic net trained models and testing results.
    %   - Nperm
    %     Number of premutations.
    %   - intrim_csv
    %     Full path of the intermediate csv file generated by hcp2block2 function.
    %   - restricted_csv 
    %     Full path of the HCP restricted csv file, containing the family structure information. 
    %   - subj_ls
    %     Full subject list (absolute path).
    %
    % Author: Jingwei Li
    
    addpath(fullfile(getenv('CBIG_CODE_DIR'), 'external_packages', 'matlab', 'non_default_packages', 'palm', 'palm-alpha109'))
    
    
    %% create permutations
    % 1. use `hcp2blocks.m` to generate block definitions
    % 2. use `palm_tree.m` to create exchangeable tree
    % 3. use `palm_permtree.m` to generate permutation indices
    idx_perm_out = fullfile(LRR_dir, 'Pset.mat');
    if(~exist(idx_perm_out, 'file'))
        B = hcp2blocks(restricted_csv, intrim_csv, false, dlmread(subj_ls));
        Ptree = palm_tree(B);
        Pset = palm_permtree(Ptree, Nperm+1, false, true);
        save(idx_perm_out, 'Pset', 'B')
    end
    

    rmpath(fullfile(getenv('CBIG_CODE_DIR'), 'external_packages', 'matlab', 'non_default_packages', 'palm', 'palm-alpha109'))
    
end

